//
//  WQCMyEarningViewController.m
//  renxinghuan
//
//  Created by 王晓民 on 2018/3/23.
//  Copyright © 2018年 吴清翠. All rights reserved.
//

#import "WQCMyEarningViewController.h"
#import "configuration.h"
#import "QLCycleProgressView.h"
#import "XYWaterWaveView.h"
#import "XLPasswordView.h"
#import "BalanceDetaileViewController.h"
#import "WQCBankViewController.h"
@interface WQCMyEarningViewController ()<XLPasswordViewDelegate>
@property (nonatomic, strong) QLCycleProgressView *progressView;
@property(nonatomic,strong)UILabel *amoutLb;
@property(nonatomic,strong) UILabel* nameLable;

@property(nonatomic,strong)  UILabel *mothLable;


@end

@implementation WQCMyEarningViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = wycMain;
    [self setupNav];
    [self loadProfit];
    
    _amoutLb = [MyUIClass makeUILabelWithFrame:CGRectMake(0, 200, ScreenWidth, 50) andBackColor:[UIColor clearColor] andText:@"0.00" andTextColor:[UIColor whiteColor] andFont:[UIFont boldSystemFontOfSize:30] andAlignment:NSTextAlignmentCenter];
    [self.view addSubview:_amoutLb];
    
    UILabel *yuan = [MyUIClass makeUILabelWithFrame:CGRectMake(0, _amoutLb.frame.origin.y+_amoutLb.frame.size.height+10, ScreenWidth, 50) andBackColor:[UIColor clearColor] andText:@"余额（元）" andTextColor:[UIColor whiteColor] andFont:[UIFont systemFontOfSize:14] andAlignment:NSTextAlignmentCenter];
    [self.view addSubview:yuan];

    
    UIButton * backButton = [[UIButton alloc] init];
    backButton.frame = CGRectMake(80 * px, 1100 * px, ScreenWidth - 160 * px, 150 * px);
    [backButton addTarget:self action:@selector(pressMoney) forControlEvents:UIControlEventTouchUpInside];
    [backButton setTitle:@"提现" forState:UIControlStateNormal];
    backButton.titleLabel.font = [UIFont systemFontOfSize:BigFont];
    [backButton setTitleColor:wycMain forState:UIControlStateNormal];
    backButton.layer.cornerRadius = 75 * px;
    backButton.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:backButton];
    UILabel *name = [[UILabel alloc] init];
    name.frame = CGRectMake(0, CGRectGetMaxY(backButton.frame) + 180 * px, [UIScreen mainScreen].bounds.size.width / 2, 20);
    name.text = @"今日收益";
    name.font = [UIFont systemFontOfSize:50 * px];
    name.textColor = [UIColor whiteColor];
    name.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:name];
    
    
  _nameLable= [[UILabel alloc] init];
    _nameLable.frame = CGRectMake(name.x, CGRectGetMaxY(name.frame) + 40 * px, [UIScreen mainScreen].bounds.size.width / 2, 20);
    _nameLable.text = @"0.00";
    _nameLable.font = [UIFont systemFontOfSize:50 * px];
    _nameLable.textColor = [UIColor whiteColor];
    _nameLable.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:_nameLable];
    
    
    UILabel *moth = [[UILabel alloc] init];
    moth.frame = CGRectMake([UIScreen mainScreen].bounds.size.width / 2, name.y, [UIScreen mainScreen].bounds.size.width / 2, 20);
    moth.text = @"累计收益";
    moth.font = [UIFont systemFontOfSize:50 * px];
    moth.textColor = [UIColor whiteColor];
    moth.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:moth];
    
   _mothLable = [[UILabel alloc] init];
    _mothLable.frame = CGRectMake([UIScreen mainScreen].bounds.size.width / 2, _nameLable.y, [UIScreen mainScreen].bounds.size.width / 2, 20);
    _mothLable.text = @"0.00";
    _mothLable.font = [UIFont systemFontOfSize:50 * px];
    _mothLable.textColor = [UIColor whiteColor];
    _mothLable.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:_mothLable];
    
    
//   
//    XYWaterWaveView *waveView = [[XYWaterWaveView alloc] initWithFrame:CGRectMake(0, ScreenHeight - 120, ScreenWidth, 120)];
//    [self.view addSubview:waveView];
    
}
#pragma mark    -   XLPasswordViewDelegate

/**
 *  输入密码位数已满时调用
 */
- (void)passwordView:(XLPasswordView *)passwordView didFinishInput:(NSString *)password
{
    NSLog(@"输入密码位数已满,在这里做一些事情,例如自动校验密码%@",password);
    
    [self loadMoney:password];
    
}
-(void)loadMoney:(NSString *)paypass
{
    NSMutableDictionary * params = [NSMutableDictionary dictionary];
    paypass = [RSA encryptString:paypass publicKey:RSA_P_KEY];
    
    
    params[@"payPassword"] = paypass ;
    [HttpTool POST:withdraw params:params success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSLog(@"%@",responseObject);
        if ([[responseObject objectForKey:@"code"] intValue] == 0)
        {
            [SVProgressHUD showImage:nil status:@"提现成功"];
            [self.navigationController popViewControllerAnimated:YES];
        }else{
            
            [SVProgressHUD showImage:nil status:msgStr];
        }
        
    } fail:^(NSURLSessionDataTask *task, NSError *error) {
    }];
}

//提现
-(void)pressMoney
{
    
    if ([self.amoutLb.text intValue]>0)
    {
     
     if ([[WYCAccountTool unarchivehavePayPassword] isEqualToString:@"1"])
    {
        //未设置支付密码
        WQCBankViewController  *codeView = [[WQCBankViewController alloc]init];
        [self.navigationController pushViewController:codeView animated:YES];
    }
    else
    {
        XLPasswordView *passwordView = [XLPasswordView passwordViewWithKeyboardType:XLPasswordViewKeyboardTypeSystem];
        passwordView.delegate = self;
        [passwordView showPasswordInView:self.view];
        [passwordView.passwordInputView.textField becomeFirstResponder];
    }
    }
        else
        {
            [SVProgressHUD showImage:nil status:@"您没有提现金额"];
            return;
        }
}
#pragma make -------->>setNav
- (void)setupNav {
    self.navigationItem.title = @"我的收益";
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
       self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithTitle:@"明细" target:self action:@selector(rightClick)];

    [self.navigationController.navigationBar setBarTintColor:wycMain];
    
}
-(void)rightClick
{
    NSLog(@"收益明细");

    BalanceDetaileViewController  *balanceView = [[BalanceDetaileViewController alloc]init];
    [self.navigationController pushViewController:balanceView animated:YES];
    
}
- (QLCycleProgressView *)progressView {
    if (!_progressView) {
        _progressView = [[QLCycleProgressView alloc]initWithFrame:CGRectMake(160 * px, 200, ScreenWidth - 320 * px, _progressView.width)];
    }
    return _progressView;
}
//我的收益
-(void)loadProfit
{
    [HttpTool POST:myProfit params:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSLog(@"%@",responseObject);
        if ([[responseObject objectForKey:@"code"] intValue] == 0) {
           
            NSDictionary *result = [responseObject objectForKey:@"result"];
            _amoutLb.text = result[@"yue"];
            _nameLable.text =result[@"yesterdayShare"];
            _mothLable.text = result[@"allShare"];
            
            
//            _nameLable.text =result[@"yue"];
//            _amoutLb.text =result[@"allShare"];
//            _mothLable.text =result[@"yesterdayShare"];
            
        }else{
            
        }
        
    } fail:^(NSURLSessionDataTask *task, NSError *error) {
    }];
}

@end
